/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @signatureAlgorithm = 'v2';
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('btripopen', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ScanMsgListRequest {
  biz?: string(name='Biz'),
  channelType?: string(name='ChannelType'),
  corpId?: string(name='CorpId'),
  scanSequence?: int32(name='ScanSequence'),
  sequenceId?: long(name='SequenceId'),
  size?: int32(name='Size'),
  userId?: string(name='UserId'),
}

model ScanMsgListResponseBody = {
  code?: int32(name='Code'),
  extMsg?: string(name='ExtMsg'),
  module?: [ 
    {
      biz?: string(name='Biz'),
      content?: string(name='Content'),
      haveRedDot?: boolean(name='HaveRedDot'),
      sendTime?: string(name='SendTime'),
      sequenceId?: long(name='SequenceId'),
      showMsg?: boolean(name='ShowMsg'),
      unReadCount?: int32(name='UnReadCount'),
    }
  ](name='Module'),
  msg?: string(name='Msg'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model ScanMsgListResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ScanMsgListResponseBody(name='body'),
}

async function scanMsgList(request: ScanMsgListRequest): ScanMsgListResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return scanMsgListWithOptions(request, headers, runtime);
}

async function scanMsgListWithOptions(request: ScanMsgListRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ScanMsgListResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.biz)) {
    body['Biz'] = request.biz;
  }
  if (!Util.isUnset(request.channelType)) {
    body['ChannelType'] = request.channelType;
  }
  if (!Util.isUnset(request.corpId)) {
    body['CorpId'] = request.corpId;
  }
  if (!Util.isUnset(request.scanSequence)) {
    body['ScanSequence'] = request.scanSequence;
  }
  if (!Util.isUnset(request.sequenceId)) {
    body['SequenceId'] = request.sequenceId;
  }
  if (!Util.isUnset(request.size)) {
    body['Size'] = request.size;
  }
  if (!Util.isUnset(request.userId)) {
    body['UserId'] = request.userId;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ScanMsgList',
    version = '2022-05-17',
    protocol = 'HTTPS',
    pathname = `/ScanMsgList`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model TakeAccessTokenRequest {
  appKey?: string(name='app_key'),
  appSecret?: string(name='app_secret'),
}

model TakeAccessTokenResponseBody = {
  code?: string(name='code'),
  data?: {
    accessToken?: string(name='access_token'),
    expire?: long(name='expire'),
  }(name='data'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  success?: string(name='success'),
}

model TakeAccessTokenResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: TakeAccessTokenResponseBody(name='body'),
}

async function takeAccessToken(request: TakeAccessTokenRequest): TakeAccessTokenResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return takeAccessTokenWithOptions(request, headers, runtime);
}

async function takeAccessTokenWithOptions(request: TakeAccessTokenRequest, headers: map[string]string, runtime: Util.RuntimeOptions): TakeAccessTokenResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.appKey)) {
    query['app_key'] = request.appKey;
  }
  if (!Util.isUnset(request.appSecret)) {
    query['app_secret'] = request.appSecret;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'TakeAccessToken',
    version = '2022-05-17',
    protocol = 'HTTPS',
    pathname = `/btrip/open/access-token/take`,
    method = 'GET',
    authType = 'Anonymous',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

